
<?php 
/* 
Template Name: prosessing-xoa-may-ajax
*/
?>
<?php
if ( !is_user_logged_in() ) 
    {
      ?>

        <div id='content_nano_two' class='clearfix' style='min-height:300px;'>
              <h1 style='color:#000;'>bạn không được phép truy cập trang này </h1>
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
        </div>
         
     <?php 
          
    }//if ( ! current_user_can( 'list_users' ) ) 
    elseif (is_user_logged_in() )  
 { 

    if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      {
       ?>

        <div id='content_nano_two' class='clearfix' style='min-height:300px;'>
              <h1 style='color:#000;'>bạn không được phép truy cập trang này </h1>
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
        </div>
         
     <?php 

      }//if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
      {
     

                   
                        $id_may = $_POST['idmay'];
                        $ID = $_POST['nguoiquanli'];

                      
                       $wpdb->delete( 'wp_user_wp_may', array( 'ID' => $ID ) );
                       ?>
                       <p>
                          
                   <?php
                   global $current_user;
                  get_currentuserinfo();
                  $id_user_now = $current_user->ID;
                                           
                      $sql = "SELECT * FROM wp_user_wp_may
                                                                      INNER JOIN wp_users
                                                                                  ON wp_users.ID = wp_user_wp_may.ID
                                                                                  WHERE id_may =".$id_may."";  
                                              
                                            $row = $wpdb->get_results($sql);
                                                            
                                                              ?> 
                                                             <table class="wp-list-table widefat fixed users" cellspacing="0">
                                                                  <thead>
                                                                   <tr>
                                                                     <th scope="col" id="cb"  style=""> </th>
                                                                     <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                                                                     <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                                                                     <th scope="col" id="xoang"style=""></th>
                                                                   </tr>
                                                                  </thead>
                                                                   <tbody id="the-list" data-wp-lists="list:user">
                                                      <?php 
                                                        foreach($row as $key=>$value)
                                                       {
                 // truy van lay quyen quan tri
                   $id_user_meta_data = $wpdb->get_results("SELECT * FROM wp_usermeta WHERE user_id = ".$value->ID);

                     foreach ($id_user_meta_data as $key =>$vlue) 
                         {
                                                       
                            if ( ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}' ) or ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}' ) and ( $id_user_now === $value->ID )  ) 
                             { 
                             {
                                                       ?>
                                                            <tr id="user-<?php echo $value->ID; ?>" class="alternate">
                                                                 <th scope="row" class="check-column">
                                                                   <label class="screen-reader-text" for="cb-select-1"></label>
                                                                 </th>
                                                                   <td class="username column-username">
                                                                     <strong><?php echo $value->user_login;?></strong>
                                                                  </td>
                                                                  <td class="name column-name"><?php echo $value->display_name;?></td>
                                                                  <td class="xoang column-xoang">
                                                                    <ul style='position: relative;'>
                                                                      <li style='height: 20px;'>
                                                                        <input type='button' 
                                                                        nguoiquanli="<?php echo $value->ID; ?>"
                                                                        idmay="<?php echo  $id_may;?>" 
                                                                        id="delqli" 
                                                                        class="delqli<?php echo $value->ID; ?>" 
                                                                        value=' xóa' style='z-index: 1986;'
                                                                        name='delqli<?php echo $value->ID; ?>'
                                                                        />
                                                                      </li>
                                                                    </ul>
                                                                    <!-- onclick="if (!confirm("Bạn không xóa máy này ? chọn Click OK . Nếu bạn muốn xóa chọn HỦY")) return false;"  -->    
                                                                  </td>
                                                            </tr><!-- id="user-xyz" class="alternate" -->
                                                      <?php             
           }//  if ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}') 
        } //  foreach ($id_user_meta_data as $key =>$vlue) 
  }// foreach($row as $key=>$value)
                                                        ?>

                                                        
                                                             </tbody>
                                                                    </table>

                                    <!-- </div><!-- id='moidauload' -->
                                        
                            </p>
                             <script type="text/javascript">
                            
                               jQuery(document).ready(function(){

                                    $("td input[name^='delqli']").click(function() {
                                    var nguoiquanli = $(this).attr("nguoiquanli");
                                    var idmay = $(this).attr("idmay");
                                   
                                    $.ajax({
                                            url:"<?php bloginfo('url');?>/prosessing_xoa_may",
                                              type:"POST",
                                              data: {nguoiquanli:nguoiquanli,idmay:idmay},
                                              success: function(data)
                                              {
                                                $('#content_addqli').html(data);
                                                $('#content_addqli').show();
                                                $('#content_addqli').css('z-index','20001');
                                                //$('.wp-list-table.widefat.fixed.users').css('display','none');
                                                //$('.wp-list-table.widefat.fixed.users').css('width','800px');
                                               }
                                        });
                                    });
                                      
                                  })
                            
                </script>
                       
              <?php 
                     echo '<h1></h1>';
                     echo '<strong>xóa 1 người quản lí thành công</strong>';
                        return;
 
                        
 } //  elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
} //elseif ( ! current_user_can( 'list_users' ) ) ?>
